package com.diy.sigmund.diycommon.designpatterns.strategy.anno2;

import java.lang.annotation.Annotation;

/**
 * @author ylm-sigmund
 * @since 2021/8/27 14:58
 */
public class OrderHandlerTypeImpl implements OrderHandlerType {

    private final String source;
    private final String payMethod;

    OrderHandlerTypeImpl(String source, String payMethod) {
        this.source = source;
        this.payMethod = payMethod;
    }

    @Override
    public String source() {
        return source;
    }

    @Override
    public String payMethod() {
        return payMethod;
    }

    @Override
    public Class<? extends Annotation> annotationType() {
        return OrderHandlerType.class;
    }

    /*@Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        OrderHandlerTypeImpl that = (OrderHandlerTypeImpl) o;
        return Objects.equals(source, that.source) && Objects.equals(payMethod, that.payMethod);
    }

    @Override
    public int hashCode() {
        return Objects.hash(source, payMethod);
    }*/

    ///// 普通的方法生成无法生效
    @Override
    public int hashCode() {
        int hashCode = 0;
        hashCode += (127 * "source".hashCode()) ^ source.hashCode();
        hashCode += (127 * "payMethod".hashCode()) ^ payMethod.hashCode();
        return hashCode;
    }


    @Override
    public boolean equals(Object obj) {
        if (!(obj instanceof OrderHandlerType)) {
            return false;
        }
        OrderHandlerType other = (OrderHandlerType) obj;
        return source.equals(other.source()) && payMethod.equals(other.payMethod());
    }
}
